package cn.sunjinxin.trade.infrastructure.repository;

import cn.hutool.core.bean.BeanUtil;
import cn.sunjinxin.trade.dal.mapper.OrderMapper;
import cn.sunjinxin.trade.dal.mapper.TempOrderMapper;
import cn.sunjinxin.trade.dal.po.OrderPo;
import cn.sunjinxin.trade.dal.po.TempOrderPo;
import cn.sunjinxin.trade.domain.gateway.OrderGateway;
import cn.sunjinxin.trade.domain.gateway.TempOrderGateway;
import cn.sunjinxin.trade.domain.model.Order;
import cn.sunjinxin.trade.infrastructure.config.IdWork;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.Date;


/**
 * @author issavior
 */
@Repository
public class TempOrderRepository extends ServiceImpl<TempOrderMapper, TempOrderPo> implements TempOrderGateway {

    @Override
    public void save(Order order) {
        TempOrderPo entity = new TempOrderPo();
        order.initId(IdWork.nextId());
        BeanUtil.copyProperties(order, entity);
        entity.setVersion(0);
        entity.setCreatedTime(new Date());
        entity.setUpdatedTime(new Date());

        if (!super.save(entity)) {
            throw new RuntimeException("保存订单失败");
        }
    }
}
